﻿//********************************************************************************//
//创建日期：<创建日期，2016-09-01>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：区县办公室
//********************************************************************************//
using BLL;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.JiChuXX
{
    public partial class QuXianBGS : BasePage
    {
        #region 属性

        /// <summary>
        ///当前操作项ID
        /// </summary>
        private int QuXianBGSID
        {
            get
            {
                return Convert.ToInt32(ViewState["_QuXianBGSID"]);
            }
            set
            {
                ViewState["_QuXianBGSID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 区县办公室对象
        /// </summary>
        QS_JX_QUXIANBGS _QS_JX_QUXIANBGS = new QS_JX_QUXIANBGS();

        /// <summary>
        /// 区县办公室BLL
        /// </summary>
        QS_JX_QUXIANBGSBLL _QS_JX_QUXIANBGSBLL = new QS_JX_QUXIANBGSBLL();

        /// <summary>
        /// 行政区
        /// </summary>
        QS_JX_XINGZHENGQBLL _QS_JX_XINGZHENGQBLL = new QS_JX_XINGZHENGQBLL();
        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//第一次页面加载
            {
                InitData();
                LoadData();
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        /// <summary>
        ///绑定空表头
        /// </summary>
        /// <param name="sender"></param>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                this._QS_JX_QUXIANBGS = this._QS_JX_QUXIANBGSBLL.SelectQS_JX_QUXIANBG(id);
                e.Result = string.Join("|", e.Parameter, "0", "success", this._QS_JX_QUXIANBGS.S_XINGZHENGQBH,
                    this._QS_JX_QUXIANBGS.S_XINGZHENGQMC, this._QS_JX_QUXIANBGS.S_GONGSIBH, this._QS_JX_QUXIANBGS.S_GONGSIMC, this._QS_JX_QUXIANBGS.S_GONGSIDZ,
                    this._QS_JX_QUXIANBGS.S_YOUBIAN, this._QS_JX_QUXIANBGS.S_ZHIBIAOR, this._QS_JX_QUXIANBGS.S_ZHIBIAORDH, this._QS_JX_QUXIANBGS.S_FUZER, this._QS_JX_QUXIANBGS.S_FUZERDH);
            }
            else if (e.Parameter == "del")
            {
                _QS_JX_QUXIANBGS = _QS_JX_QUXIANBGSBLL.SelectQS_JX_QUXIANBG(id, null);
                this._QS_JX_QUXIANBGS.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._QS_JX_QUXIANBGS.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                this._QS_JX_QUXIANBGS.I_JLZT = -1;
                _SYS_LOGBLL.Log<QS_JX_QUXIANBGS>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "区县办公室", OperateState.Delete, _QS_JX_QUXIANBGS, null);
                if (_QS_JX_QUXIANBGSBLL.InsertOrUpdate(_QS_JX_QUXIANBGS, null))
                {
                    
                }
                e.Result = e.Parameter + "|0|操作成功！";
            }
            else if (e.Parameter == "saveValidate")
            {
                //判断编号是否重复
                if (_QS_JX_QUXIANBGSBLL.SelectQS_JX_QUXIANBGsDynamic(string.Format("S_XINGZHENGQBH='{0}' and ID<>{1}", this.txtXZQBH.Text, id), null).Rows.Count > 0)
                {
                    e.Result = e.Parameter + "|-1|你所输入的编号,系统中已经存在使用过,请修改！";
                }
                else
                {
                    e.Result = e.Parameter + "|0|success！";
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;                
                //添加
                if (id<=0)
                {
                    operateState = OperateState.Add;
                    _QS_JX_QUXIANBGS.ID = 0;
                    _QS_JX_QUXIANBGS.I_JLZT = 0;
                }
                //修改
                else
                {
                    //修改操作
                    operateState = OperateState.Modify;
                    _QS_JX_QUXIANBGS = _QS_JX_QUXIANBGSBLL.SelectQS_JX_QUXIANBG(id, null);
                }
                _QS_JX_QUXIANBGS.S_QUXIANBH = txtXZQBH.Text;
                _QS_JX_QUXIANBGS.S_XINGZHENGQBH = txtXZQBH.Text;
                _QS_JX_QUXIANBGS.S_XINGZHENGQMC = cmbXZQMC.Text;
                _QS_JX_QUXIANBGS.S_GONGSIBH = txtGongSiBH.Text;
                _QS_JX_QUXIANBGS.S_GONGSIMC = txtGongSiMC.Text;
                _QS_JX_QUXIANBGS.S_GONGSIDZ = txtDIZHI.Text;
                _QS_JX_QUXIANBGS.S_YOUBIAN = txtYOUBIAN.Text;
                _QS_JX_QUXIANBGS.S_ZHIBIAOR = txtZHUBR.Text ;
                _QS_JX_QUXIANBGS.S_ZHIBIAORDH = txtZhiBiaodh.Text;
                _QS_JX_QUXIANBGS.S_FUZER = txtFuZeR.Text;
                _QS_JX_QUXIANBGS.S_FUZERDH = txtFuZeRDH.Text;
                this._QS_JX_QUXIANBGS.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._QS_JX_QUXIANBGS.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _SYS_LOGBLL.Log<QS_JX_QUXIANBGS>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "区县办公室", operateState, _QS_JX_QUXIANBGS, null);
                if (_QS_JX_QUXIANBGSBLL.InsertOrUpdate(_QS_JX_QUXIANBGS, null))
                {
                   
                    e.Result = e.Parameter + "|0|保存成功！";
                }
            }
        }

        /// <summary>
        /// 加载列表
        /// </summary>
        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            this.LoadData();
        }

        #endregion

        #region 方法
        /// <summary>
        /// 数据加载
        /// </summary>
        private void InitData() 
        {
            DataTable dt = _QS_JX_XINGZHENGQBLL.SelectQS_JX_XINGZHENGQsDynamic("i_jlzt=0",null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbXZQMC.Items.Add(dt.Rows[i]["S_XINGZHENGQM"].ToString(), dt.Rows[i]["S_XINGZHENGQH"]);
            }
            //需要加上权限，，后期修改
        }


        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            this.dtSource = _QS_JX_QUXIANBGSBLL.SelectQS_JX_QUXIANBGsDynamic("I_JLZT=0", null);
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        #endregion    
    }
}